package com.example.springbootrabbitmq.cobfig;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author: wukangrong
 * @date: 2020/9/1 17:36
 * @description:
 */
@Component
public class Listener {

    @RabbitHandler
    @RabbitListener(queues = "rabbit_queue_test")
    public void immediateProcess(Message message, Channel channel) throws IOException {
        System.out.println("Receiver:" + message);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
    }
    @RabbitHandler
    @RabbitListener(queues = "rabbit_queue_test2")
    public void immediateProcess2(Message message, Channel channel) throws IOException {
        System.out.println("Receiver2:" + message);
        // 不确认后续启动还会收到信息
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
    }
}
